<?php
/**
 * Created by PhpStorm.
 * User: eugene
 * Date: 2018/3/15
 * Time: 10:38
 */

namespace App\Repos;


use App\Models\MyCar;
use App\Models\Parking;
use App\Models\Record;

class ParkingRepo
{
    public static function getEmptyParks($user_id)
    {
        
        return Parking::where('user_id',$user_id)->get()->map(function($item){
            return Record::where('ParkLot',$item->id)->exists()?0:1;
        })->sum();
        
    }
    
    public static function countParkIndex($user_id,$parking_id)
    {
        $index=0;
        
        $parkings = Parking::where('user_id',$user_id)->orderBy('id')->get();
        $i=0;
        foreach($parkings as $parking){
            
            if($parking->id == $parking_id){
                $index = $i;
                break;
            }
            $i++;
        }
        return $index;
        
    }
}